package cli.view;

import java.io.PrintWriter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

// 打印加载动画
public class LoadingIcon  {

    public static void wait(PrintWriter out, Runnable runnable) {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<?> future = executor.submit(runnable);
        char[] icons = {'-', '\\', '|', '/'};
        for (int i = 0; !future.isDone(); i++) {
            out.printf("\b%c", icons[i % icons.length]);
            try {
                Thread.sleep(200);
            } catch (InterruptedException ignored) {

            }
        }
        out.print("\r");
    }
}
